*********************************************************************************
* Replication materials for 
*
* Richard Traunm�ller, Andreas Murr &  Jeff Gill 
* "Modeling Latent Information in Voting Data with Dirichlet Process Priors"
* Political Analysis
*
* Version:  October 7th 2014
*
* Requires: ZA5302_en_v6-0-0.dta (available from the GESIS website: 
*           www.gesis.org/wahlen/gles/
*
**********************************************************************************
* load data
  clear  set mem 20m
* set working directory here  use ZA5302_en_v6-0-0.dta* select people that are older than 18  keep if ragelt18==0   ***********  * migration************ gained citizenship  recode vn2a (2=1)(1=0)(98 99=.), gen(newcitizen)* speak german at home spoken at home    recode vn85a (1 100=0) (17=1) (99=.), gen(otherlanguage)* create country variable for respondent and her parents* recode old and new states into germany   recode vn82a vn295a vn298a (2 3=1) (98/100=.), gen(countryresp countryfath countrymoth)     lab def countryl 1"Germany" ///    2"Old federal states, Federal Republic of Germany" ///    3"New federal states, German Democratic Republic" ///    4"Former German territories in eastern Europe" ///    5"France/Monaco" ///    6"Turkey" ///    7"Benelux" ///    8"North Europe (EFTA)" ///    10"Iberian Peninsula" ///    12"Italy/Malta/San Marino" ///    13"GB/IRE" ///    14"Austria" ///    16"Poland" ///    17"Other Central/East Europe" ///    18"Balkan States (not EU)" ///    19"Russia" ///    20"Other GUS" ///    21"Canada/USA" ///    23"South America" ///    24"Middle East" ///    25"Africa" ///    26"China" ///    27"Asia (without China)" ///    81"Foreign/other country"  lab val countryresp countryl  lab val countryfath countryl  lab val countrymoth countryl* add information about those who said both * parents were born in Germany (vn294)  replace countryfath = 1 if vn294==1  replace countrymoth = 1 if vn294==1* where respondent and his parents born in germany?    recode countryresp countryfath countrymoth (4/81=0), ///    gen(germanyresp germanyfath germanymoth)* a person has a migration background if* she or at least one of his parents were* born outside Germany  gen migrbckgr = .  replace migrbckgr = 0 if germanyresp==1 & germanyfath==1 & germanymoth==1    replace migrbckgr = 1 if germanyresp==0 | germanyfath==0 | germanymoth==0    lab val migrbckgr binl* first and second generation  gen firstgeneration = 0  replace firstgeneration = 1 if migrbckgr==1 & germanyresp==0  gen secondgeneration = 0  replace secondgeneration = 1 if migrbckgr==1 & germanyresp==1* country of migration background  gen countrymigration = .  replace countrymigration = countryresp if countryresp>=5 & countryfath<=4 & countrymoth<=4  replace countrymigration = countryfath if countryresp<=4 & germanyfath==0 & countrymoth<=4  replace countrymigration = countrymoth if countryresp<=4 & countryfath<=4 & countrymoth>=5  replace countrymigration = countryresp if countryresp>=5 & countryresp==countryfath & countryresp==countrymoth  replace countrymigration = countrymoth if countryresp==countrymoth & countryresp>=5 & countryfath<=4  replace countrymigration = countryfath if countryresp==countryfath & countryresp>=5 & countrymoth<=4  replace countrymigration = countrymoth if countryresp<=4 & countryfath==countrymoth & countrymoth>=5  lab val countrymigration countryl* small country of origin 
* if at least one member is from a small country  recode countryresp countrymoth countryfath (6 16/20=0) (else=1), ///    gen(smallresp smallmoth smallfath)  gen smallcountry = 0  replace smallcountry = 1 if migrbckgr==1 & (smallresp==1 | smallmoth==1 | smallfath==1)* unfree country of origin* if at least one member is from an unfree country* system of migration* aussiedler: russia, gus, poland, austria (without balkan)  recode countryresp countrymoth countryfath (4 14/17 19/20=1) (else=0), ///    gen(aussiedler_resp aussiedler_moth aussiedler_fath)  gen aussiedler = 0  replace aussiedler = 1 if migrbckgr==1 & (aussiedler_resp==1 | aussiedler_moth==1 | aussiedler_fath==1)  recode countryresp countrymoth countryfath (6 10 12 17 18 25=1) (else=0), ///    gen(guestworker_resp guestworker_moth guestworker_fath)  gen guestworker = 0  replace guestworker = 1 if migrbckgr==1 & (guestworker_resp==1 | guestworker_moth==1 | guestworker_fath==1)********** turnout********** turnout  recode n111 (2=0) (98 99 102=.), gen(turnout)  replace turnout = 1 if n111==102 & (v252==1 | v252==6)  replace turnout = 0 if n111==102 & v252==5  * education* code "other" (2 obs.) as missing  recode vn9a (1 2=0)(3/5=1)(97 99=.), gen(educ)  replace educ = 0 if vn10a==1  replace educ = 1 if vn10a==4* female  recode vn1 (2=1) (1=0), gen(female)* age   gen age = vn542  * employment  recode vn17 (1/5 7 8 12/14=1) (6 9/11 15=0) (99=.), gen(employ)* membership in trade union or club  recode n86a - n86h (1 98 99=0) (2 3 =1), ///    gen(m1 m2 m3 m4 m5 m6 m7 m8)  gen member = 0  replace member = 1 if m1==1 | m2==1 | m3==1 | ///    m4==1 | m5==1 | m6==1 | m7==1 | m8==1* interest   recode vn217 (1=5) (2=4) (4=2) (5=1) (98 99=.), ///    gen(interest)* strength of partisanship  recode vn136 (1=5) (2=4) (4=2) (5=1) ///    (98 99=.) (100=0), gen(strengthpid)* knowledge  gen know1 = 0  gen know2 = 0  replace know1 = 1 if vn125==2  replace know2 = 1 if vn126==5      gen know = know1 + know2* civic duty  recode vn130e (98 99 = .), gen(civicduty)* difference in evaluation  recode vn165a vn165c (98 99 = .), gen(evalcdu evalspd)  gen absdiffeval = abs(evalcdu - evalspd)* democratic satisfaction  recode vn291 (1=5) (2=4) (4=2) (5=1) ///    (98 99=.) (100=0), gen(satisf)* own current financial situation  recode vn179 (1=5)(2=4)(4=2)(5=1)(98 99 = .), gen(financial)  * class  recode vn76 (98 99 = .), gen(class)************** vote choice************** vote choice and pid* 1 = cdu/csu, 2 = spd, 3 = fdp, 4 = grn, * 5 = linke, 6 = oth, 7 = none/not applicable  recode vn135a v254_1a v254_2a n169_1a n169_2a ///    (1/3=1) (4=2) (5=3) (6=4) (7=5) ///    (801 802=6) (808 809 1000=7) (998 999 1002=.), ///    gen(pid firstvote_pre secondvote_pre firstvote_post secondvote_post)  gen firstvote = firstvote_pre  replace firstvote = firstvote_post if v254_1a==1002  gen secondvote = secondvote_pre  replace secondvote = secondvote_post if v254_2a==1002  lab define votel 1"cdu" 2"spd" 3"fdp" 4"grn" 5"lnk" 6"oth" 7"non"  lab val firstvote votel  lab val secondvote votel  lab val pid votel* self-employed and worker  recode vn21 vn28 (1/3 8=1)(4/7=0)(98/100=.), gen(selfemplnow selfemplpast)  gen selfempl = selfemplnow  replace selfempl = selfemplpast if selfemplnow==.    recode vn21 vn28 (1/5 7/8=0) (6=1) (98/100=.), gen(workernow workerpast)  gen worker = workernow  replace worker = workerpast if workernow==.* denomination and church attendance    recode vn79 (1=1) (2 3=2) (5=3) (6/8=0) (98 99=.), gen(denomination)  lab def denom_l 0"none" 1"catholic" 2"protestant" 3"other"  lab val denom denom_l  recode denom (0 2 3=0), gen(catholic)  recode denom (0 1 3=0) (2=1), gen(protestant)  recode denom (0/2=0) (3=1), gen(other)      recode vndkirchg (100=0) (98 99=.), gen(attendance)* issues  recode vn190 vn193 vn195 vn151 (98 99 100=.), ///    gen(leftright spending immigration nuclear) * select variable  keep survey1 newcitizen otherlanguage migrbckgr firstgeneration secondgeneration smallcountry ///    aussiedler guestworker ///    turnout educ female age employ member interest strengthpid know civicduty ///    absdiffeval satisf financial class firstvote secondvote pid selfempl worker ///    catholic protestant other attendance leftright spending immigration nuclear* save data  save GlesWuestReplication.dta, replace* end source code  exit 